<%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<div class="block small left">
    
    <div class="block_head">
        <div class="bheadl"></div>
        <div class="bheadr"></div>
        <h2>Details of sale "<bean:write name="sale" property="saleID"/>"</h2>
    </div>
    <!-- .block_head ends -->
    
    <div class="block_content clearfix">
        
        <logic:notEmpty name="errorMessages" >
            <div class="message errormsg">
                <logic:iterate id="message" name="errorMessages">
                    <p><bean:write name="message"/></p>
                </logic:iterate>
            </div>
        </logic:notEmpty>
        <logic:notEmpty name="successMessages" >
            <div class="message success">
                <logic:iterate id="message" name="successMessages">
                    <p><bean:write name="message"/></p>
                </logic:iterate>
            </div>
        </logic:notEmpty>
        <html:form action="admin/sale.do" method="post">
            <h2>Flat</h2><br/>
            <html:hidden property="saleID"/>
            <p>
                <label>ID: </label>
                <span class="text"><bean:write name="flat" property="flatID"/></span>
            </p>
            <p>
                <label>Flat Name: </label>
                <span class="text"><bean:write name="flat" property="flatName"/></span>
            </p>
            <p>
                <label>Floor Number: </label>
                <span class="text"><bean:write name="flat" property="floorNumber"/></span>
            </p>
            <p>
                <label>Area: </label>
                <span class="text"><bean:write name="flat" property="area"/>
                &nbsp;sq.foot</span>
            </p>
            <hr/>
            <br/><br/>
            <h2>Sale</h2><br/>
            <p>
                <label>Status: </label>
                <span class="text"><bean:write name="sale" property="statusName"/></span>.&nbsp;&nbsp;&nbsp;
                <logic:equal name="sale" property="saleStatus" value="BR">
                    <html:hidden property="action" value="reg"/>
                    <html:submit value="Register Now" styleClass="submit mid"/>
                </logic:equal>
            </p>
            <p>
                <label>ID: </label>
                <span class="text"><bean:write name="sale" property="saleID"/></span>
            </p>
            <p>
                <label>Payment Mode: </label>
                <span class="text"><bean:write name="sale" property="paymentModeName"/></span>
            </p>
            <p>
                <label>Customer Name: </label>
                <span class="text"><bean:write name="sale" property="customerName"/></span>
            </p>
            <p>
                <label>Customer Phone: </label>
                <span class="text"><bean:write name="sale" property="customerPhone"/></span>
            </p>
            <p>
                <label>Customer Address: </label>
                <span class="text"><bean:write name="sale" property="customerAddress"/></span>
            </p>
            <p>
                <label>Stamp Duty & Registration Charged: </label>
                <logic:greaterThan name="sale" property="sdCharge" value="0">
                    <span class="text"><bean:write name="sale" property="customerAddress"/></span>
                </logic:greaterThan>
                <logic:lessEqual name="sale" property="sdCharge" value="0">
                    <span class="text">Not Registerred!</span>
                </logic:lessEqual>
            </p>
            <p>
                <label>Total Cost: </label>
                <span class="text"><fmt:formatNumber value="${sale.totalCost}"/>
                &nbsp;U.S. dollars</span>
            </p>
            <p>
                <label>Total Payment: </label>
                <span class="text"><fmt:formatNumber value="${sale.totalPayment}"/>
                &nbsp;U.S. dollars</span>
            </p>
            <p>
                <label>Total Amount Paid: </label>
                <span class="text"><fmt:formatNumber value="${sale.totalAmountPaid}"/>
                &nbsp;U.S. dollars</span>
            </p>
            <p>
                <label>Total Amount Due: </label>
                <span class="text"><fmt:formatNumber value="${sale.totalAmountDue}"/>
                &nbsp;U.S. dollars</span>
            </p>
            <p><label>Description:</label></p>
            <div>
                ${sale.description}
            </div>
        </html:form>
        <hr/>
        
        <html:form styleId="saleForm" action="admin/sale.do" method="post">
            <p>
                <html:hidden property="saleID" />
                <html:submit property="action" value="Edit" styleClass="submit"/>
                <html:link styleClass="confirm-button submit small red" action="/admin/saleListing.do?action=delete" paramId="saleID" paramName="saleForm" paramProperty="saleID">
                    Delete
                </html:link>
                <html:link action="/admin/saleListing.do" styleClass="submit long gray">Back to the list</html:link>
            </p>
        </html:form>
        
        
    </div>
    <!-- .block_content ends -->
    
    <div class="bendl"></div>
    <div class="bendr"></div>
    
</div>
<!-- .block.small.left ends -->


<div class="block small right">
    
    <div class="block_head">
        <div class="bheadl"></div>
        <div class="bheadr"></div>
        
        <h2>Payments</h2>
    </div>
    <!-- .block_head ends -->

    
    <div class="block_content clearfix">
        <logic:equal name="sale" property="saleStatus" value="NR">
            <html:link styleClass="submit mid" action="/admin/sale.do?action=addPay" paramId="saleID" paramName="sale" paramProperty="saleID">
                Add Payment
            </html:link>
        </logic:equal>
        <logic:empty name="paymentList">
            <p class="align-center">There are no payments</p>
        </logic:empty>
        <logic:notEmpty name="paymentList">
            <table cellpadding="0" cellspacing="0" width="100%" class="sortable">
                <thead>
                    <th>Created On</th>
                    <th>Amount Due</th>
                    <th>Due Date</th>
                    <th>Amount Paid</th>
                    <td>&nbsp;</td>
                </thead>
                <tbody>
                    <logic:iterate id="payment" name="paymentList">
                        <tr>
                            <td><fmt:formatDate type="date" value="${payment.createdDate}"/></td>
                            <td><fmt:formatNumber type="CURRENCY" value="${payment.amountDue}"/></td>
                            <td><fmt:formatDate type="date" value="${payment.dueDate}"/></td>
                            <td><fmt:formatNumber type="CURRENCY" value="${payment.amountPaid}"/></td>
                            <td>                                    
                                <html:link action="/admin/sale.do?action=editPay&amp;payID=${payment.payID}" paramId="saleID" paramName="sale" paramProperty="saleID">
                                    Edit
                                </html:link>
                            </td>
                        </tr>
                    </logic:iterate>
                </tbody>
                
            </table>
        </logic:notEmpty>
        
    </div>
    <!-- .block_content ends -->
    
    <div class="bendl"></div>
    <div class="bendr"></div>
    
</div>
<!-- .block.small.right ends -->
